package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.media.bean.AudioBean;

public class MusicAdapter extends StkProviderMultiAdapter<AudioBean>{

    public MusicAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(82));
        addItemProvider(new MusicProvider());
    }

    private class MusicProvider extends BaseItemProvider<AudioBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_music;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, AudioBean bean) {
            baseViewHolder.setText(R.id.tvMusicItemName, bean.getName());
            baseViewHolder.setText(R.id.tvMusicItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getPath()), new SimpleDateFormat("yyyy/MM/dd")));
            baseViewHolder.setText(R.id.tvMusicItemSize,ConvertUtils.byte2FitMemorySize(bean.getSize()));
            if (bean.isSelected()) {
                baseViewHolder.getView(R.id.ivMusicItemSelOn).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivMusicItemSelOff).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.ivMusicItemSelOn).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivMusicItemSelOff).setVisibility(View.VISIBLE);
            }
        }
    }

}
